<template>
    <transition name="modal-fade">
        <div class="modal-backdrop" @click="closeModalByMask($event)">
            <div class="modal"
                role="dialog"
                aria-labelledby="modalTitle"
                aria-describedby="modalDescription"
            >
                <header class="modal-header" id="modalTitle">
                    <slot name="header">
                        This is the default title!
                    </slot>
                </header>
                <section class="modal-body" id="modalDescription">
                    <slot name="body">
                        This is a default body!
                    </slot>
                </section>
                <footer class="modal-footer">
                    <slot name="footer">
                        This is the default footer!
                    </slot>
                    <!-- <button type="button" class="btn-green" @click="close" aria-label="Close modal">Close Modal</button> -->
                </footer>
            </div>
        </div>
    </transition>
</template>

<script>
export default {
  name: 'Modal',
  methods:{
    closeModalByMask(event){
        let that = this
        if(event.target.className == 'modal-backdrop'){
            that.close()
        }
    },
    close(){
        this.$emit('close')
    }
  },
  data() {
    return {

    }
  },
  components: {

  }
}
</script>

<style scoped>
    .modal-backdrop{
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10;
        background-color: rgba(0,0,0,0.3);
        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* overflow-x是为了什么？ */
    .modal{
        background-color: #FFFFFF;
        box-shadow: 2px 2px 20px 1px;
        overflow-x: auto;
        display: flex;
        flex-direction: column;

        width: 90vw;
        background-color: #ffd24d;
        border: 12px solid #fff;
        border-radius: 40px;
    }

    .modal-header,
    .modal-footer{
        padding: 15px;
        display: flex;
    }

    .modal-header{
        position: relative;
        justify-content: center;
        font-size: 40px;
        font-weight: bold;
    }

    .modal-footer{
        flex-direction: column;
        justify-content: flex-end;
    }

    .modal-body{
        position: relative;
        padding: 20px 10px;
        color:#8c6800;
        font-weight: bold;
    }

    /* modal的渐变 */
    .modal-fade-enter,
    .modal-fade-leave-to {
    opacity: 0;
    }

    .modal-fade-enter-active,
    .modal-fade-leave-active {
    transition: opacity .5s ease;
    }
</style>
